package com.example.universitylibraryback.dto;

import lombok.Data;
@Data
public class ResultDTO<T> {
    private int code;
    private String message;
    private T data;
    private long timestamp; // 添加时间戳
    
    // 构造函数
    public ResultDTO() {
        this.timestamp = System.currentTimeMillis();
    }
    
    public static <T> ResultDTO<T> success(T data) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(200);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }
    
    public static <T> ResultDTO<T> fail(int code, String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    
    // 添加常用的失败方法
    public static <T> ResultDTO<T> badRequest(String message) {
        return fail(400, message);
    }
    
    public static <T> ResultDTO<T> unauthorized(String message) {
        return fail(401, message);
    }
    
    public static <T> ResultDTO<T> forbidden(String message) {
        return fail(403, message);
    }
    
    public static <T> ResultDTO<T> notFound(String message) {
        return fail(404, message);
    }
    
    public static <T> ResultDTO<T> internalError(String message) {
        return fail(500, message);
    }
}
